package project.euler;


/**
 * The prime factors of 13195 are 5, 7, 13 and 29.<br>
 * What is the largest prime factor of the number 600851475143 ?
 *  
 * @author Shekhar
 *
 */
public class PE3 {
	
	public static void main(String[] args) {
		long number = 600851475143l;
		int largestPrimeFactor = 0;
		
		for(int i = 2;i<= number;i++){
			while(number % i == 0){
				number = number/i;
				if(isPrimeNumber(i)){
					largestPrimeFactor = i;
				}
			}
		}
		System.out.println(largestPrimeFactor);
	}

	private static boolean isPrimeNumber(int number){
		if(number == 1 || number == 2){
			return true;
		}
		for(int i = 2; i < number;i++){
			int remainder = number % i;
			if((remainder == 0)){
				return false;
			}
		}
		return true;
	}
}
